#include "ValueWithError.h"
#include <cmath>
#include "sqr.h"

ValueWithError::ValueWithError(void):
	val(0), error(0)
{
}

ValueWithError::ValueWithError(float v, float e):
	val(v), error(e)
{
}


ValueWithError::~ValueWithError(void)
{
}

ValueWithError operator-(ValueWithError &a, ValueWithError &b)
{
	ValueWithError res;
	res.val = a.val - b.val;
	res.error = a.error + b.error;
	return res;
}

ValueWithError operator/(ValueWithError &a, ValueWithError &b)
{
	ValueWithError res;
	res.val = a.val / b.val;
	res.error = std::sqrt( sqr(a.error/b.val) + sqr(b.error*a.val / sqr(b.val)) );
	return res;
}
